package com.geo;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import com.calque.CalqueSitesClientTempMosqueAjouter;
import com.commun.AjouterMosque;
import com.commun.Param;
import com.commun.MyMediaPlayer;
import com.commun.Utils;
import com.google.android.maps.MapView;

public class MyMapView extends MapView {

	private long lastTouchTime = -1;
	Context mContext;

	public MyMapView(Context context, AttributeSet attrs) {

		super(context, attrs);
		mContext = context;

	}

	public Context getmContext() {
		return mContext;
	}

	public void setmContext(Context mContext) {
		this.mContext = mContext;
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		if (AjouterMosque.isTaptagOnMapDetected) {
			AjouterMosque.isTaptagOnMapDetected = false;
			AjouterMosque.SetTagIconToDK_Grey();
		}
		if (AjouterMosque.isTagButtonActivate) {

			AjouterMosque.tapMosqueGeoPoint = CalqueSitesClientTempMosqueAjouter
					.getInstance().getMapView().getProjection().fromPixels(
							(int) ev.getX(), (int) ev.getY());

			CalqueSitesClientTempMosqueAjouter.getInstance().getMapView()
					.getController().animateTo(AjouterMosque.tapMosqueGeoPoint);
			CalqueSitesClientTempMosqueAjouter.getInstance().animationLaunched = true;
			AjouterMosque.isTagButtonActivate = false;
			AjouterMosque.isTaptagOnMapDetected = true;
			AjouterMosque.SetTagIconToDK_Grey();
		}

		Utils.dismissToasts(mContext);

		if (ev.getAction() == MotionEvent.ACTION_DOWN) {

			long thisTime = System.currentTimeMillis();
			if (thisTime - lastTouchTime < 250) {

				// Double tap
				this.getController().zoomInFixing((int) ev.getX(),
						(int) ev.getY());
				this.getController().zoomInFixing((int) ev.getX(),
						(int) ev.getY());
				lastTouchTime = -1;

			} else {
				lastTouchTime = thisTime;
			}
		}

		return super.onInterceptTouchEvent(ev);

	}

	int oldZoomLevel = Param.ZOOM_LEVEL;
	Boolean zoomIntial = false;

	@Override
	public void dispatchDraw(Canvas canvas) {
		super.dispatchDraw(canvas);
		if (oldZoomLevel == Param.ZOOM_LEVEL && !zoomIntial)
			zoomIntial = true;
		else if (getZoomLevel() > oldZoomLevel && zoomIntial) {
			MyMediaPlayer mediaPlayer = new MyMediaPlayer();
			mediaPlayer.initSounds(getContext());
			mediaPlayer.playSound(MyMediaPlayer.TypeSounde.ZOOM_IN);

			oldZoomLevel = getZoomLevel();
		}
	}

}